package com.cuckoo.cuckoo_app2.utils;

import com.cuckoo.cuckoo_app2.config.ApiConfig;
import com.google.gson.Gson;

import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

public class SignUtil {

    public static String getParamsSign(Map<String, String> map) {
        SortedMap<String, String> params = new TreeMap<>(map);
        Gson gson = new Gson();
        String paramsJsonStr = gson.toJson(params);
        String signatureSecret = new ApiConfig().SIGNATURESECRET;

        try {
            MD5Utils md5Utils = new MD5Utils();
            String s = md5Utils.md5DigestAsHex(paramsJsonStr + signatureSecret);
            return s.toUpperCase();
        } catch (Exception e) {
            return null;
        }
    }
}
